/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cmp.player.abilities;

import static com.cmp.core.constants.InputUIDConstants.ABILITY_BUTTON_UID;
import static com.cmp.core.constants.UIDConstants.BALL_UID;
import com.cmp.player.controls.CharacterRigidBodyControl;
import com.cmp.player.controls.CursorSelectionControl;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;

/**
 *
 * @author krummer
 */
public class AssBombControl extends AbilityControl {

    private static final float DROP_SPEED = -2;
    
    private CharacterRigidBodyControl body;
    private boolean isAbility;
    
    @Override
    public void setSpatial(Spatial spatial) {
        super.setSpatial(spatial);
        super.setCooldown(3.f);
        super.setCastDuration(1.f);

        spatial.setUserData(ABILITY_BUTTON_UID, false);
        this.body = spatial.getControl(CharacterRigidBodyControl.class);
    }

    @Override
    public void execute() {
        //only if player hasn't the ball or isn't on ground (implying he has to jump first or drops of higher terain)
        if (body.isOnGround() || ((Node) this.spatial).getChild(BALL_UID) != null) {
            return;
        }
        super.activateCooldown();
        super.activateGCD();
        super.activateCastTime();
        
        body.setLinearVelocity(Vector3f.UNIT_Y.mult(DROP_SPEED));
        damagePlayers();
    }

    private void damagePlayers(){
        //compute who was hit
        //drop ball on hit player if possible
    }
    
    @Override
    protected void controlUpdate(float tpf) {
        super.controlUpdate(tpf);
        
        isAbility = super.getSpatial().getUserData(ABILITY_BUTTON_UID);
        if(isAbility) {
            execute();
        }
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
    }

    public Control cloneForSpatial(Spatial spatial) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
